# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
export CHECKFUNC=1

_pkgname=libcst
pkgname=python-libcst
pkgver=0.4.9
pkgrel=4
pkgdesc="A concrete syntax tree parser and serializer library for Python that preserves many aspects of Python's abstract syntax tree"
arch=('loong64' 'x86_64')
url='https://github.com/Instagram/LibCST'
license=('MIT')
depends=(
  'glibc'
  'gcc-libs'
  'python'
  'python-typing_extensions'
  'python-typing_inspect'
  'python-pyyaml'
)
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools-rust'
  'python-setuptools-scm'
  'python-wheel'
  'ufmt'
)
checkdepends=(
  'python-hypothesis'
  'python-hypothesmith'
  'python-pytest'
)
source=("https://pypi.io/packages/source/l/libcst/libcst-$pkgver.tar.gz")
sha512sums=('f4f6b89ae06b319d8a7ce29e3a2446318b587684adcc80fae32fd4cf4cb3744ef20e11543d38b27622b4b748df1ca4f829d23cf0327f0f4639c93a4fc118c4df')

prepare() {
  cd $_pkgname-$pkgver

  # generate code for tests
  sed -i 's/subprocess.check_call/subprocess.run/' libcst/codegen/generate.py
  python -m libcst.codegen.generate all
}

build() {
  cd $_pkgname-$pkgver

  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    --ignore libcst/tests/test_fuzz.py
    --deselect libcst/metadata/tests/test_type_inference_provider.py::TypeInferenceProviderTest::test_gen_cache_0
    --deselect libcst/metadata/tests/test_type_inference_provider.py::TypeInferenceProviderTest::test_simple_class_types_0
    --deselect libcst/metadata/tests/test_type_inference_provider.py::TypeInferenceProviderTest::test_with_empty_cache
  )
  cd $_pkgname-$pkgver

  pytest -vv "${pytest_options[@]}"
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_pkgname-$pkgver

  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  # remove tests
  rm -frv "$pkgdir/$site_packages/$_pkgname/"{tests,metadata/tests}
}

# vim:set ts=2 sw=2 et:
